package com.rockxin.cat.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.rockxin.cat.R;
import com.rockxin.cat.adapter.PagerAdapter;
import com.rockxin.cat.base.BaseActivity;
import com.rockxin.cat.bean.LendRecordBean;
import com.rockxin.cat.customview.NoScrollViewPager;
import com.rockxin.cat.fragment.LendRecordFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 出借记录
 */
public class LendRecordActivity extends BaseActivity {

    @BindView(R.id.back_img)
    ImageView backImg;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.returnedMoney)
    TextView returnedMoney;
    @BindView(R.id.settle)
    TextView settle;
    @BindView(R.id.viewPager)
    NoScrollViewPager viewPager;

    private LendRecordActivity mLendRecordActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mLendRecordActivity = this;
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_lend_record;
    }

    @Override
    public void initData() {
        title.setText("出借记录");
        List<Fragment> frameLayoutList = new ArrayList<>();
        LendRecordBean lendRecordBean = new LendRecordBean();
        lendRecordBean.setNum("序号");
        lendRecordBean.setName("项目");
        lendRecordBean.setRepay_money("出借金额");
        lendRecordBean.setRepay_time("出借时间");

        frameLayoutList.add(LendRecordFragment.newInstance(lendRecordBean, 3));
        frameLayoutList.add(LendRecordFragment.newInstance(lendRecordBean, 3));

        viewPager.setOffscreenPageLimit(frameLayoutList.size());
        viewPager.setNoScroll(true);
        viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager(), frameLayoutList));
    }

    @OnClick({R.id.back_img, R.id.returnedMoney, R.id.settle})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_img:
                finish();
                break;
            case R.id.returnedMoney:
                returnedMoney.setTextColor(ContextCompat.getColor(mLendRecordActivity, R.color.colorPrimary));
                settle.setTextColor(ContextCompat.getColor(mLendRecordActivity, R.color.colorTextColor));
                viewPager.setCurrentItem(0, false);
                break;
            case R.id.settle:
                settle.setTextColor(ContextCompat.getColor(mLendRecordActivity, R.color.colorPrimary));
                returnedMoney.setTextColor(ContextCompat.getColor(mLendRecordActivity, R.color.colorTextColor));
                viewPager.setCurrentItem(1, false);
                break;
        }
    }
}
